﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <el-form ref="formRefIssueRecord" :model="stateIssueRecord.vmModel" label-width="100px">
    <div style="margin-bottom:10px;">{{$t('message.autotrans.SysBatchEditConfirm')}}</div>
    <el-row>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_StationId_FormItem" prop="LinkedVM.StationId" :label="$t('message.autotrans._Model_IssueRecord_Station')">
          <el-select v-model="stateIssueRecord.vmModel.LinkedVM.StationId" clearable>
             <el-option v-for="item in stateIssueRecord.AllStations" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_OpId_FormItem" prop="LinkedVM.OpId" :label="$t('message.autotrans._Model_IssueRecord_OpId')">
          <el-input v-model="stateIssueRecord.vmModel.LinkedVM.OpId" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_OpName_FormItem" prop="LinkedVM.OpName" :label="$t('message.autotrans._Model_IssueRecord_OpName')">
          <el-input v-model="stateIssueRecord.vmModel.LinkedVM.OpName" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_IssueTypeId_FormItem" prop="LinkedVM.IssueTypeId" :label="$t('message.autotrans._Model_IssueRecord_IssueType')">
          <el-select v-model="stateIssueRecord.vmModel.LinkedVM.IssueTypeId" clearable>
             <el-option v-for="item in stateIssueRecord.AllIssueTypes" :key="item.Value" :value="item.Value" :label="item.Text"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_IssueTypeName_FormItem" prop="LinkedVM.IssueTypeName" :label="$t('message.autotrans._Model_IssueRecord_IssueTypeName')">
          <el-input v-model="stateIssueRecord.vmModel.LinkedVM.IssueTypeName" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_ReportTime_FormItem" prop="LinkedVM.ReportTime" :label="$t('message.autotrans._Model_IssueRecord_ReportTime')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_IssueRecord_ReportTime')}), trigger: 'blur' }]" >
          <el-date-picker v-model="stateIssueRecord.vmModel.LinkedVM.ReportTime" type='date' clearable></el-date-picker>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Reporter_FormItem" prop="LinkedVM.Reporter" :label="$t('message.autotrans._Model_IssueRecord_Reporter')">
          <el-input v-model="stateIssueRecord.vmModel.LinkedVM.Reporter" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Description_FormItem" prop="LinkedVM.Description" :label="$t('message.autotrans._Model_IssueRecord_Description')">
          <el-input v-model="stateIssueRecord.vmModel.LinkedVM.Description" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Handler_FormItem" prop="LinkedVM.Handler" :label="$t('message.autotrans._Model_IssueRecord_Handler')">
          <el-input v-model="stateIssueRecord.vmModel.LinkedVM.Handler" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_HandleTime_FormItem" prop="LinkedVM.HandleTime" :label="$t('message.autotrans._Model_IssueRecord_HandleTime')">
          <el-date-picker v-model="stateIssueRecord.vmModel.LinkedVM.HandleTime" type='date' clearable></el-date-picker>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_HandleResult_FormItem" prop="LinkedVM.HandleResult" :label="$t('message.autotrans._Model_IssueRecord_HandleResult')">
          <el-input v-model="stateIssueRecord.vmModel.LinkedVM.HandleResult" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Status_FormItem" prop="LinkedVM.Status" :label="$t('message.autotrans._Model_IssueRecord_Status')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_IssueRecord_Status')}), trigger: 'blur' }]" >
          <el-select v-model="stateIssueRecord.vmModel.LinkedVM.Status" clearable>
             <el-option key="Pending" value="Pending" :label="$t('message.autotrans._Enum_IssueStatusEnum_Pending')"></el-option>
             <el-option key="Handling" value="Handling" :label="$t('message.autotrans._Enum_IssueStatusEnum_Handling')"></el-option>
             <el-option key="Resolved" value="Resolved" :label="$t('message.autotrans._Enum_IssueStatusEnum_Resolved')"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Remark_FormItem" prop="LinkedVM.Remark" :label="$t('message.autotrans._Model_IssueRecord_Remark')">
          <el-input v-model="stateIssueRecord.vmModel.LinkedVM.Remark" clearable></el-input>
      </el-form-item>

      </el-col>
    </el-row>

    <div style="text-align:right;">
      <WtmButton @click="onSubmitIssueRecord"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

      <WtmButton @click="onCloseIssueRecord"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

    </div>

  </el-form>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageAndonManagementIssueRecordBatchEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { issuerecordApi } from '/@/api/andonmanagement/issuerecord';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefIssueRecord = ref();
const stateIssueRecord = reactive({
    vmModel: {
	  LinkedVM:{
        StationId: null,
        OpName: '',
        IssueTypeId: null,
        IssueTypeName: '',
        ReportTime: undefined,
        Reporter: '',
        Description: '',
        Handler: '',
        HandleTime: undefined,
        HandleResult: '',
        Status: undefined,
        Remark: '',
      },
      Ids:[],
      
	},
    
    AllStations: [] as any[],
    AllIssueTypes: [] as any[],
});

// 取消
const onCloseIssueRecord = () => {
    closeDialog();
};

// 提交
const onSubmitIssueRecord = () => {
	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});

    formRefIssueRecord.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            issuerecordApi().batchedit(stateIssueRecord.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error:any) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};


// 页面加载时
onMounted(() => {
    
    other.getSelectList('/api/AndonManagement/IssueRecord/GetAndonStations',[],false).then(x=>{stateIssueRecord.AllStations = x});
    other.getSelectList('/api/AndonManagement/IssueRecord/GetIssueTypes',[],false).then(x=>{stateIssueRecord.AllIssueTypes = x});
    if (ci.attrs["wtmdata"]) {
		stateIssueRecord.vmModel.Ids = ci.attrs["wtmdata"];
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateIssueRecord.vmModel.Ids = useRouter().currentRoute.value.query.id as any;
	}

});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

